package org.class2table.z_running_data;

import org.class2table.core.util.DataSourceUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 构建数据源建议使用@org.class2table.core.util.DataSourceUtil工具
 *      使用@org.class2table.core.util.DataSourceUtil工具构建的全部数据源，
 *      可以在程序执行完毕后统一使用@org.class2table.core.util.DataSourceUtil.release()方法释放资源
 */
public class DefaultSyncData {

    /**
     * 租户数据源，key为数据库名字，value为该数据库连接 @java.sql.Connection 对象
     */
    public static Map<String, Connection> tenantConnectionMap = new HashMap<>();
    static {
        try {
            tenantConnectionMap.put("db1", DataSourceUtil.getConnection("jdbc:mysql://localhost:3306/db1?serverTimezone=UTC","root","123456"));
//            tenantConnectionMap.put("db2", getConnection("","",""));
        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException("DefaultSyncData create tenantConnectionMap failed!", e);
        }
    }

    public static Connection masterConnection;
    static {
        try {
            masterConnection = DataSourceUtil.getConnection(
                        "jdbc:mysql://localhost:3306/information_schema?serverTimezone=UTC",
                        "root",
                        "123456");
        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException("DefaultSyncData create masterConnection failed!", e);
        }
    }

    public static List<Class<?>> inputClazz;

    static {
        inputClazz = Arrays.asList(
                User.class
        );
    }

}